import { createRouter, createWebHashHistory } from 'vue-router'
import PageStructure from '@/components/Main/PageStructure.vue'
import BlogsPage from '@/components/Blog/BlogsPage.vue'
import BlogPage from '@/components/Blog/BlogPage.vue'
import ReleasePage from '@/components/Blog/Release/ReleasePage.vue'
import UserPage from '@/components/User/UserPage.vue'
import LoginComp from '@/components/User/LoginComp.vue'
import RegistComp from '@/components/User/RegistComp.vue'
import NotePage from '@/components/Note/NotePage.vue'
import RelationPage from '@/components/Relation/RelationPage.vue'
import SettingPage from '@/components/Setting/SettingPage.vue'
import AboutPage from '@/components/About/AboutPage.vue'
import TestPage from '@/components/Test/TestPage.vue'

import QQRedirectPage from '@/components/User/QQRedirectPage.vue'


let router = createRouter({
  // 内部提供了 history 模式的实现。这里使用 hash 模式。
  history: createWebHashHistory(),
  routes: [
    {
      name: "Blogs", path: '/', component: PageStructure,
      children: [
        {
          name: 'Blogs', path: '/home', component: BlogsPage,
          meta: { }
        }, {
          name: "Blog", path: '/blog', component: BlogPage,
          meta: { name: '博客页' }
        }, {
          name: "Release", path: '/release', component: ReleasePage,
          meta: { name: '发布' }
        }, {
          name: "User", path: '/user', component: UserPage,
          meta: { name: '用户' }
        }, {
          name: "Note", path: '/note', component: NotePage,
          meta: { isPage: true, name: '日记' }
        }, {
          name: "Relation", path: '/relation',
          component: RelationPage, meta: { name: '人际关系' }
        }, {
          name: "Setting", path: '/setting', component: SettingPage,
          meta: { isPage: true, name: '设置' }
        }, {
          name: "Test", path: '/test',
          component: TestPage, meta: { name: '测试页面' }
        }, {
          name: "About", path: '/about',
          component: AboutPage, meta: { name: '关于本站' }
        },
      ]
    }, {
      name: "Login", path: '/login',
      component: LoginComp, meta: { name: '登录' }
    }, {
      name: "Regist", path: '/regist',
      component: RegistComp, meta: { name: '注册' }
    }, {
      name: "QQRedirect", path: '/qq-redirect',
      component: QQRedirectPage, meta: { name: 'QQ登录' }
    },
  ],

})

router.beforeEach((to, from, next) => {
  if (to.path === '/') next('/home')
  // 改变标题栏       
  if (to.meta.name) document.title = to.meta.name + ' - MyLog'
  else document.title = 'MyLog - 把你写成书'
  document.documentElement.scrollTop = 0
  next()
})

export default router